//
//  MyGoodsCell.m
//  jingdongfang
//
//  Created by MTiMac02 on 2018/1/3.
//  Copyright © 2018年 LJL. All rights reserved.
//

#import "MyGoodsCell.h"
#import "IGMyGoods.h"
#import "SaleGoodsVC.h"

@implementation MyGoodsCell
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.goodsView=[[UIView alloc]init];
        self.goodsImageV=[[UIImageView alloc]init];
        self.goodsLabel=[[UILabel alloc]init];
        self.priceLabel=[[UILabel alloc]init];
        self.soldOutBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.soldOutBtn setEnabled:YES];
    };
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    IGMyGoods *list=self.data;
    [self.contentView addSubview:self.goodsView];
    [self.goodsView addSubview:self.goodsImageV];
    [self.goodsView  addSubview:self.goodsLabel];
    [self.goodsView addSubview:self.priceLabel];
    [self.goodsView addSubview:self.soldOutBtn];
    
    self.goodsView.frame=CGRectMake(0, 0, 180*KSCREENWIDTH/375, 270*KSCREENWIDTH/375);
    self.goodsImageV.frame=CGRectMake(0, 0, 180*KSCREENWIDTH/375, 180*KSCREENWIDTH/375);
    self.goodsLabel.frame=CGRectMake(0, self.goodsImageV.bottom+5*KSCREENWIDTH/375, self.goodsImageV.width, 16);
    self.priceLabel.frame=CGRectMake(0, self.goodsLabel.bottom+5*KSCREENWIDTH/375, self.goodsLabel.width, 14);
    self.soldOutBtn.frame=CGRectMake(0, self.priceLabel.bottom+8*KSCREENWIDTH/375, 70, 35*KSCREENWIDTH/375);
    
    self.goodsImageV.contentMode = UIViewContentModeScaleAspectFit;
    [self.goodsImageV sd_setImageWithURL:[NSURL URLWithString:list.images] placeholderImage:[UIImage imageNamed:@"new"]];
    self.goodsLabel.font = [UIFont font16];
    self.goodsLabel.textAlignment = NSTextAlignmentCenter;
    self.goodsLabel.textColor = [UIColor c4Color];
    self.goodsLabel.text=list.title;
    
    self.priceLabel.font = [UIFont boldSystemFontOfSize:14];
    self.priceLabel.textAlignment = NSTextAlignmentCenter;
    self.priceLabel.textColor = [UIColor c4Color];
    self.priceLabel.text=[NSString stringWithFormat:@"¥%@",list.price];
    
    [self.soldOutBtn setTitle:@"下架" forState:UIControlStateNormal];
    [self.soldOutBtn setTitleColor:[UIColor c1Color] forState:UIControlStateNormal];
    self.soldOutBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [self.soldOutBtn.layer setCornerRadius:15.f];
    [self.soldOutBtn.layer setBorderColor:[UIColor c1Color].CGColor];
    [self.soldOutBtn.layer setBorderWidth:1.0];
    self.soldOutBtn.centerX=self.goodsView.centerX;
    self.soldOutBtn.contentEdgeInsets = UIEdgeInsetsMake(6,3,6,3);
     [self.soldOutBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    if ([list.status integerValue]==2) {//已上架
        [self.soldOutBtn setTitle:@"下架" forState:UIControlStateNormal];
        [self.soldOutBtn.layer setCornerRadius:15.f];
        [self.soldOutBtn.layer setBorderColor:[UIColor c1Color].CGColor];
        [self.soldOutBtn.layer setBorderWidth:1.0];
        [self.soldOutBtn setEnabled:YES];
    }else if ([list.status integerValue]==4){//已下架
        [self.soldOutBtn setTitle:@"已下架" forState:UIControlStateNormal];
        [self.soldOutBtn.layer setBorderColor:[UIColor clearColor].CGColor];
        [self.soldOutBtn setEnabled:NO];
    }else if ([list.status integerValue]==1){//待审核
        [self.soldOutBtn setTitle:@"待审核" forState:UIControlStateNormal];
        [self.soldOutBtn.layer setBorderColor:[UIColor clearColor].CGColor];
        [self.soldOutBtn setEnabled:NO];
    }else if ([list.status integerValue]==3){//审核不通过
        [self.soldOutBtn setTitle:@"审核不通过" forState:UIControlStateNormal];
        [self.soldOutBtn sizeToFit];
        [self.soldOutBtn.layer setBorderColor:[UIColor clearColor].CGColor];
        [self.soldOutBtn setEnabled:NO];
    }
    
//    self.goodsImageV.backgroundColor = [UIColor lightGrayColor];
    self.goodsView.backgroundColor=[UIColor whiteColor];
    self.goodsLabel.backgroundColor=[UIColor whiteColor];
    self.priceLabel.backgroundColor=[UIColor whiteColor];
    self.soldOutBtn.backgroundColor=[UIColor whiteColor];
}
-(void)btnClick{
//    [self.soldOutBtn setEnabled:NO];
     self.soldGoods();
//    [self.soldOutBtn setTitle:@"已下架" forState:UIControlStateNormal];
//    [self.soldOutBtn.layer setBorderColor:[UIColor clearColor].CGColor];


    
}
- (void)awakeFromNib
{
    [super awakeFromNib];
}
@end
